from django.db import models
from datetime import datetime
from customer.models import PayOrderModel

# Create your models here.


# 骑手user表
class RiderModel(models.Model):
    r_name = models.CharField(max_length=32, verbose_name="用户名", unique=True)
    mobile = models.CharField(max_length=16, verbose_name="手机号", unique=True)
    password = models.CharField(max_length=555,verbose_name='密码',default='')
    img = models.CharField(max_length=256, verbose_name="头像")
    login_time = models.DateTimeField(default=datetime.now, verbose_name="登录时间")
    gender = models.CharField('性别', max_length=16, default='')
    reg_time = models.DateTimeField(default=datetime.now, verbose_name="注册时间")
    intro = models.CharField(max_length=256, default="这个人懒，什么也没写", verbose_name="用户简介")
    real_name = models.CharField(max_length=64, verbose_name="真实姓名",default='')
    status = models.CharField(max_length=64, verbose_name="身份证号",default='')
    hand_identity = models.CharField('手持身份证', max_length=999, default='')
    identity_front = models.CharField('身份证正面', max_length=999, default='')
    identity_reverse = models.CharField('身份证反面', max_length=999, default='')
    is_audit = models.IntegerField('是否审核（0待审核 1审核通过 2审核驳回 3未提交）', default=3)
    cause_down = models.CharField('驳回原因', max_length=256, default='')
    balance = models.DecimalField('余额',max_digits=13,decimal_places=2,default=0.00)
    freeze = models.IntegerField('是否冻结（1冻结 2不冻结）', default=2)
    change_time = models.DateTimeField('更改时间', default=datetime.now())
    delete = models.BooleanField('是否删除 0否 1是', default=0)

    def __str__(self):
        return self.r_name

    class Meta:
        db_table = 'rider_model'


# 抢单大厅
class OrderLobbyModel(models.Model):
    o_id = models.ForeignKey(to=PayOrderModel,on_delete=models.CASCADE,verbose_name='订单ID')
    status = models.CharField(max_length=16,default=0,verbose_name='0 待抢单，1 已抢单')

    def __str__(self):
        return self.status

    class Meta:
        db_table = 'order_lobby_model'


# 骑手订单表
class RiderOrderModel(models.Model):
    order_id = models.ForeignKey(to=PayOrderModel,on_delete=models.CASCADE,verbose_name='订单ID')
    rider = models.ForeignKey(to=RiderModel, on_delete=models.CASCADE, verbose_name='所属骑手')
    status = models.CharField(max_length=16,default='0',verbose_name='0抢单 1待取单 2配送中 3已完成')
    establish_time = models.DateTimeField('创建时间', default=datetime.now())
    change_time = models.DateTimeField('更改时间', default=datetime.now())
    delete = models.BooleanField('是否删除 0否 1是', default=0)

    def __str__(self):
        return self.status

    class Meta:
        db_table = 'rider_order_model'

